﻿using System;
using Birkelund.QueryStrings;
using NUnit.Framework;

namespace Birkelund.QueryStrings.Test
{
    public class QueryStringConfigurationTest
    {
        [SetUp]
        public void Init()
        {
            QueryStringConfiguration.Instance.RemoveFullEncryption();
        }

        [TearDown]
        public void CleanUp()
        {
            QueryStringConfiguration.Instance.RemoveFullEncryption();
        }

        [Test]
        public void SingletonTest()
        {
            Assert.AreSame(QueryStringConfiguration.Instance, QueryStringConfiguration.Instance);
        }

        #region Full encryption
        [Test]
        public void SetFullEncryptionTest()
        {
            Assert.IsNull(QueryStringConfiguration.Instance.Encryptor, "Encrypt is not null");

            QueryStringConfiguration.Instance.SetFullEncryption(new DesEncryptionImpl());

            Assert.IsNotNull(QueryStringConfiguration.Instance.Encryptor, "Encrypt is null");
        }

        [Test]
        public void RemoveFullEncryptionTest()
        {
            QueryStringConfiguration.Instance.SetFullEncryption(new DesEncryptionImpl());
            QueryStringConfiguration.Instance.RemoveFullEncryption();

            Assert.IsNull(QueryStringConfiguration.Instance.Encryptor, "Encrypt is not null");
        }

        [Test]
        public void SetDefaultFullEncryptionTest()
        {
            QueryStringConfiguration.Instance.SetFullEncryption();

            Assert.IsNotNull(QueryStringConfiguration.Instance.Encryptor, "Encrypt is null");
        }

        [Test]
        public void SetFullEncryptionTest_Null()
        {
            QueryStringConfiguration.Instance.SetFullEncryption(null);

            Assert.IsNull(QueryStringConfiguration.Instance.Encryptor, "Encrypt is not null");
        } 

        #endregion

        [Test]
        public void ChecksumCalculator_NullNotAllowed()
        {
            Assert.IsNotNull(QueryStringConfiguration.Instance.ChecksumCalculator, "Initial value is null");
            Assert.Throws<ArgumentNullException>(() =>  QueryStringConfiguration.Instance.ChecksumCalculator = null);
        }
    }
}
